﻿<UserControl x:Class="MultiColumnTreeListSample.MainPage"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" 
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
             xmlns:common="clr-namespace:System.Windows;assembly=System.Windows.Controls"
    xmlns:d="http://schemas.microsoft.com/expression/blend/2008" xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" 
             xmlns:data="clr-namespace:System.Windows.Controls;assembly=System.Windows.Controls.Data"  
             xmlns:radiantq="clr-namespace:RadiantQ.Windows.Controls;assembly=MultiColumnTreeListSrc"
             xmlns:controls="clr-namespace:System.Windows.Controls;assembly=System.Windows.Controls"
             xmlns:local="clr-namespace:MultiColumnTreeListSample"
    mc:Ignorable="d" d:DesignWidth="640" d:DesignHeight="480">
  <Grid x:Name="LayoutRoot">
        <Grid.Resources>

            <local:TaskNameConverter x:Name="nameConverter"/>
            <local:TwoWayTaskNameConverter x:Name="twoWayNameConverter"/>

            <local:DateConverter x:Name="dateConverter"/>
            <local:TwoWayDateConverter x:Name="twoWayDateConverter"/>

            <!-- Tree templates.
            The MultiColumnTreeList control relies on the FlatteningTreeView instance to flatten the hierarchy, which is defined
            by the HierarchicalDataTemplates below. 
            -->
            <DataTemplate x:Key="TreeLeafTemplate">
                <TextBlock Text="{Binding Path=TaskName}" />
            </DataTemplate>
            <common:HierarchicalDataTemplate x:Key="TreeProjectsTemplate" ItemsSource="{Binding Path=Tasks}"
                                             ItemTemplate="{StaticResource TreeLeafTemplate}">
                <TextBlock Text="{Binding Path=PName}" />
            </common:HierarchicalDataTemplate>
            <common:HierarchicalDataTemplate x:Key="TreeProductsTemplate" ItemsSource="{Binding Path=Projects}"
                                             ItemTemplate="{StaticResource TreeProjectsTemplate}">
                <TextBlock Text="{Binding Path=PDName}" />
            </common:HierarchicalDataTemplate>
            
        </Grid.Resources>
        <Grid.RowDefinitions>
            <RowDefinition Height="Auto"></RowDefinition>
            <RowDefinition Height="*"></RowDefinition>
        </Grid.RowDefinitions>
            <Grid.ColumnDefinitions>
            <ColumnDefinition Width="20*"></ColumnDefinition>
            <ColumnDefinition Width="60*"></ColumnDefinition>
            <ColumnDefinition Width="20*"></ColumnDefinition>
        </Grid.ColumnDefinitions>
        <StackPanel Margin="5" Orientation="Horizontal" Grid.ColumnSpan="3">
            <Button Content="Tree Visibility Toggle" Click="HideTree_Click"></Button>
        </StackPanel>
        <radiantq:FlatteningTreeView Grid.Row="1" Grid.Column="0" x:Name="flatteningTreeView" RowHeight="25" HeaderHeight="25" TitleContent="Projects"
                                     ItemTemplate="{StaticResource TreeProductsTemplate}"
                                     AutoExpandNodes="False"
                                     ></radiantq:FlatteningTreeView>
        <radiantq:MultiColumnTreeList Grid.Row="1" Grid.Column="1" x:Name="multiColumnTreeList" RowHeight="25"  Margin="7,0,0,0">
            <radiantq:MultiColumnTreeList.Columns>

                <data:DataGridTemplateColumn Header="Name">
                    <data:DataGridTemplateColumn.CellTemplate>
                        <!-- DataContext for the DataTemplates here will be an instance of FlexyNodeData.-->
                        <DataTemplate>
                            <!-- Use an ExpandableTextBlock in the first column to include the expand/collapse cue.-->
                            <radiantq:ExpandableTextBlock Text="{Binding Data, Converter={StaticResource nameConverter}}"></radiantq:ExpandableTextBlock>
                        </DataTemplate>
                    </data:DataGridTemplateColumn.CellTemplate>
                    <data:DataGridTemplateColumn.CellEditingTemplate>
                        <DataTemplate>
                            <radiantq:ExpandableTextBox Text="{Binding Data, Converter={StaticResource twoWayNameConverter}, Mode=TwoWay}"></radiantq:ExpandableTextBox>
                        </DataTemplate>
                    </data:DataGridTemplateColumn.CellEditingTemplate>
                </data:DataGridTemplateColumn>

                <data:DataGridTemplateColumn Header="StartTime">
                    <data:DataGridTemplateColumn.CellTemplate>
                        <!-- DataContext for the DataTemplates here will be an instance of FlexyNodeData.-->
                        <DataTemplate>
                            <TextBlock VerticalAlignment="Center" Text="{Binding Data, Converter={StaticResource dateConverter}, ConverterParameter='AsText'}"></TextBlock>
                        </DataTemplate>
                    </data:DataGridTemplateColumn.CellTemplate>
                    <data:DataGridTemplateColumn.CellEditingTemplate>
                        <DataTemplate>
                            <controls:DatePicker VerticalAlignment="Center" SelectedDate="{Binding Data, Converter={StaticResource twoWayDateConverter}, Mode=TwoWay}" />
                        </DataTemplate>
                    </data:DataGridTemplateColumn.CellEditingTemplate>
                </data:DataGridTemplateColumn>
            </radiantq:MultiColumnTreeList.Columns>
        </radiantq:MultiColumnTreeList>
        <controls:GridSplitter Grid.Column="1" Grid.Row="1" 
                               Width="7" VerticalAlignment="Stretch" HorizontalAlignment="Left"
                               ShowsPreview="True" x:Name="GridSplitter1"
                                />
        <StackPanel Grid.Row="1" Grid.Column="2" Margin="7,0,0,0" Orientation="Vertical" ScrollViewer.HorizontalScrollBarVisibility="Auto">
            <TextBlock Text="Selected Item Information:" FontWeight="Bold" Margin="5"></TextBlock>
            <StackPanel Orientation="Horizontal">
                <TextBlock Text="Name:" Margin="5"></TextBlock>
                <TextBlock x:Name="slName" Margin="5"></TextBlock>
            </StackPanel>
            <StackPanel Orientation="Horizontal">
                <TextBlock Text="Type:" Margin="5"></TextBlock>
                <TextBlock x:Name="slType" Margin="5"></TextBlock>
            </StackPanel>
        </StackPanel>
      <controls:GridSplitter Grid.Column="2" Grid.Row="1" 
                               Width="7" VerticalAlignment="Stretch" HorizontalAlignment="Left"
                               ShowsPreview="True"
                                />
    </Grid>
</UserControl>
